//
//  UIBarButtonItem+Extensions.swift
//  微博
//
//  Created by 陈明光 on 2019/11/7.
//  Copyright © 2019 陈明光. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    //fontSize:默认 16号
    //isBack: 是否是返回按钮，如果是加上箭头
    convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector,isBack: Bool = false){
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
          //isBack: 是否是返回按钮，如果是加上箭头
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: UIControl.State(rawValue: 0))
             btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
